package com.imau.brand.common.entity;

import lombok.Data;

/**
 * @author: jianl
 * @date: 2022/4/14
 * @desc: 统一结果返回类
 **/
@Data
public class ResultEntity {


    /**
     * 操作是否成功标记位
     */
    private boolean success;
    /**
     * 响应消息
     */
    private String messge;
    /**
     * 响应状态码
     */
    private int code;
    /**
     * 响应数据
     */
    private Object data;

    public ResultEntity(boolean success, String messge, int code, Object data) {
        this.success = success;
        this.messge = messge;
        this.code = code;
        this.data = data;
    }

    public ResultEntity(boolean success, String messge, int code) {
        this.success = success;
        this.messge = messge;
        this.code = code;
        this.data = data;
    }

    public ResultEntity(ResultCode resultCode) {
        this.success = resultCode.getSuccess();
        this.messge = resultCode.getMessge();
        this.code = resultCode.getCode();

    }

    public ResultEntity(ResultCode resultCode, Object data) {
        this.success = resultCode.getSuccess();
        this.messge = resultCode.getMessge();
        this.code = resultCode.getCode();
        this.data = data;

    }

    /**
     * 常见操作响应写成静态方法
     */
    public static ResultEntity SUCCESS() {

        return new ResultEntity(ResultCode.SUCCESS);
    }

    public static ResultEntity SUCCESS(Object data) {

        return new ResultEntity(ResultCode.SUCCESS, data);
    }


    public static ResultEntity ERROR() {
        return new ResultEntity(ResultCode.SERVER_ERROR);
    }

    public static ResultEntity FAIL() {
        return new ResultEntity(ResultCode.FAIL);
    }
}